package com.inmaytide.website.service.system;

import com.inmaytide.website.domain.entities.system.SysLog;
import com.inmaytide.website.utils.log.annotation.LogInformation;
import com.inmaytide.website.utils.pagination.Pagination;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author luomiao
 * @since May 25, 2016
 */
public interface SysLogService {

    String[] SEARCH_CONDITIONS_KEYS = {"operator", "content", "optime_begin", "optime_end"};

    default Map<String, String> createConditions(HttpServletRequest request) {
        Map<String, String> conditions = new HashMap<String, String>();
        Arrays.stream(SEARCH_CONDITIONS_KEYS).forEach(s -> conditions.put(s, request.getParameter(s)));
        return conditions;
    }

    void delete(Integer id);

    /**
     * 按主键ID批量删除
     *
     * @param ids
     */
    void deleteBatch(Integer... ids);

    /**
     * 清空所有日志
     */
    void deleteBatch();

    /**
     * AOP切面日志操作成功记录
     *
     * @param annotation
     */
    void insert(LogInformation annotation, String methodName);

    /**
     * AOP切面日志操作失败
     *
     * @param annotation
     * @param e          异常对象
     */
    void insert(LogInformation annotation, Throwable e, String methodName);

    void insert(SysLog log);

    /**
     * 多条件查询日志列表并分页
     *
     * @param request
     * @param pagination 分页和查询条件相关信息
     * @return
     */
    Pagination<SysLog> findList(HttpServletRequest request, Pagination<SysLog> pagination);


    void export(String type, Pagination<SysLog> pagination, OutputStream os) throws IOException;
}
